/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package com.lineage.server.model.item.etcitem.action;

import com.lineage.configure.Config;
import com.lineage.server.PacketCreate;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.item.ItemExecutor;
import com.lineage.server.packetserver.S_ServerMessage;
import com.lineage.server.utils.Random;

/**
 * Class <code>SeikoSoilWaterFireWindDrill</code> 精工的土、水、火、风之钻 - (40943 - 40958).
 * 
 * @author jrwz
 * @version 2012-6-19上午11:54:01
 * @see com.lineage.server.model.item.etcitem.action
 * @since JDK1.7
 */
public final class SeikoSoilWaterFireWindDrill extends ItemExecutor {

    /**
     * 取得实例.
     * 
     * @return 实例
     */
    public static ItemExecutor get() {
        return new SeikoSoilWaterFireWindDrill();
    }

    /** 精工的土、水、火、风之钻 - (40943 - 40958). */
    private SeikoSoilWaterFireWindDrill() {
    }

    @Override
    public void execute(final L1PcInstance pc, final L1ItemInstance useItem,
            final int readC1, final int readC2, final int targetId,
            final int targetX, final int targetY) {
        final int itemId = useItem.getItemId();
        final int itemobj = targetId;
        final L1ItemInstance l1iteminstance1 = pc.getInventory().getItem(
                itemobj);
        final int ringId = l1iteminstance1.getItem().getItemId();
        int ringlevel = 0;
        int gmas = 0;
        int gmam = 0;

        // 精致的属性戒指类
        if ((ringId >= 41185) && (41200 >= ringId)) {
            // 精工的土、水、火、风之钻类
            switch (itemId) {
                case 40943:
                case 40947:
                case 40951:
                case 40955:
                    gmas = 443;
                    gmam = 447;
                    break;

                case 40944:
                case 40948:
                case 40952:
                case 40956:
                    gmas = 442;
                    gmam = 446;
                    break;

                case 40945:
                case 40949:
                case 40953:
                case 40957:
                    gmas = 441;
                    gmam = 445;
                    break;

                case 40946:
                case 40950:
                case 40954:
                case 40958:
                    gmas = 444;
                    gmam = 448;
                    break;
            }
            if (ringId == (itemId + 242)) {
                if ((Random.nextInt(99) + 1) < Config.CREATE_CHANCE_PROCESSING_DIAMOND) {
                    ringlevel = 20435 + (ringId - 41185);
                    pc.sendPackets(new S_ServerMessage(gmas, l1iteminstance1
                            .getName()));
                    pc.createNewItem(pc, ringlevel, 1);
                    pc.getInventory().removeItem(l1iteminstance1, 1);
                    pc.getInventory().removeItem(useItem, 1);
                } else {
                    pc.sendPackets(new S_ServerMessage(gmam, useItem.getName()));
                    pc.getInventory().removeItem(useItem, 1);
                }
            } else {
                PacketCreate.get().sendSinglePackets(pc, "没有任何事情发生");
            }
        } else {
            PacketCreate.get().sendSinglePackets(pc, "没有任何事情发生");
        }
    }
}
